package com.linyu.huawei.simple;

import java.util.Scanner;

/**
 * IPv4 地址转换成整数
 * @author 23087
 */
public class IPv4AddressTranslation {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入iPv4字符（格式如：100#101#1#5）：");
        String ipv4 = sc.next();
        // 将字符分割
        String[] arr = ipv4.split("#");
        if (arr.length != 4){
            System.out.println("invalid IP");
            return;
        }

        int first = Integer.parseInt(arr[0]);
        int second = Integer.parseInt(arr[1]);
        int third = Integer.parseInt(arr[2]);
        int fourth = Integer.parseInt(arr[3]);

        int sum = 0;
        sum = first * 256 * 256 * 256 + second * 256 * 256 + third * 256 + fourth;
        System.out.println("ipv4地址转换后为：" + sum);


    }


}
